using TMPro;
using UnityEngine;
using UnityEngine.UI;

//这是一个用于显示不同类型信息的脚本
public class HUD : MonoBehaviour
{
    public enum InfoType { Exp, Level, Kill, Time, Health } // 信息类型枚举

    public InfoType type; // 当前信息类型
    TextMeshProUGUI myText; // 文本组件
    Slider mySlider; // 滑动条组件

    void Awake()
    {
        myText = GetComponent<TextMeshProUGUI>();
        mySlider = GetComponent<Slider>();
    }

    void LateUpdate()
    {
        switch (type)
        {
            case InfoType.Exp:
                // 处理经验信息逻辑
                float curExp = GameManager.instance.exp;
                float maxExp = GameManager.instance.nextExp[Mathf.Min(GameManager.instance.level, GameManager.instance.nextExp.Length - 1)];
                mySlider.value = curExp / maxExp;
                break;
            case InfoType.Level:
                // 处理等级信息逻辑
                myText.text = "Lv." + GameManager.instance.level;
                break;
            case InfoType.Kill:
                // 处理击杀信息逻辑
                myText.text = GameManager.instance.kill.ToString();
                break;
            case InfoType.Time:
                // 处理时间信息逻辑
                float remainTime = GameManager.instance.maxGameTime - GameManager.instance.gameTime;
                int min = Mathf.FloorToInt(remainTime / 60);
                int sec = Mathf.FloorToInt(remainTime % 60);
                myText.text = min + ":" + sec;
                break;
            case InfoType.Health:
                // 处理生命值信息逻辑
                float curHeadlth = GameManager.instance.health;
                float maxHealth = GameManager.instance.maxHealth;
                mySlider.value = curHeadlth / maxHealth;
                break;
        }
    }
}